package com.qdaily.supportlibrary;

import android.app.Application;
import android.content.Context;
import android.provider.Settings;
import cn.jpush.android.api.JPushInterface;
import cn.sharesdk.framework.ShareSDK;
import com.qdaily.supportlibrary.request.RequestCacheManager;
import com.qdaily.supportlibrary.util.*;

/**
 * 各種工具類的封裝。
 * by Felix
 */
public class QdailyCodeApp {

    private static QdailyCodeApp instance;

    private Application mApplication;

    public static void onCreate(Application app, boolean isDebugMode) {
        instance = new QdailyCodeApp(app, isDebugMode);
    }

    private QdailyCodeApp(Application application, boolean isDebugMode) {
        mApplication = application;

        // local display
        LocalDisplay.init(application);

        // network status
        NetworkStatusManager.init(application);

        // image status
        ImageUtil.getInstance().init(application);

        // Logger init
        Logger.init().setMethodCount(3).setLogLevel(isDebugMode ? Logger.LogLevel.FULL : Logger.LogLevel.NONE);

        // request cache
        RequestCacheManager.init(application, "request-cache", 1024 * 10, 1024 * 50);

        // init local cache, just use default
//                CacheManagerFactory.initDefaultCache(application, null, -1, -1);

        //cube-sdk log enable
        CubeDebug.DEBUG_CACHE = isDebugMode;
        CubeDebug.DEBUG_IMAGE = isDebugMode;
        CubeDebug.DEBUG_REQUEST = isDebugMode;
        CubeDebug.DEBUG_SCROLL_HEADER_FRAME = isDebugMode;
        CubeDebug.DEBUG_PAGE_INDICATOR = isDebugMode;
        CubeDebug.DEBUG_LIST = isDebugMode;
        CubeDebug.DEBUG_LIFE_CYCLE = isDebugMode;

        //Jpush
        JPushInterface.setDebugMode(isDebugMode);    // 设置开启日志,发布时请关闭日志
        JPushInterface.init(application);            // 初始化 JPush

        //share sdk
        ShareSDK.initSDK(application);
    }

    public static QdailyCodeApp getInstance() {
        return instance;
    }

    public Context getContext() {
        return mApplication;
    }

    public String getAndroidId() {
        String id = Settings.Secure.getString(mApplication.getContentResolver(), Settings.Secure.ANDROID_ID);
        return id;
    }
}
